#include "os_init_thread.h"

#include "app_uart.h"
#include "app_oled.h"
#include "app_hw_i2c.h"
#include "app_hs300x.h"
#include "app_isl29035.h"
#include "app_common.h"
#include "app_rtc.h"
#include "app_led.h"

#define INIT_OS_DEBUG

#ifdef INIT_OS_DEBUG
#include <stdio.h>
#endif


/* os_init_thread entry function */
/* pvParameters contains TaskHandle_t */
void os_init_thread_entry(void * pvParameters)
{
	FSP_PARAMETER_NOT_USED(pvParameters);

	/* TODO: add your own code here */
	EventBits_t event_group_bits;
	EventBits_t setting_event_group;

	/* Initialize the uart for implement the 'printf' and 'scanf' */
	Uart_Init();
	/* Initialize the I2c */
	I2c_Init();
	/* Initialize the RTC */
	Rtc_Init();
	/* Initialize the LED */
	Led_Init();
	
#ifdef INIT_OS_DEBUG
	printf("===Gateway in RA4M2 by hehung, Compiler@[%s, %s]===\n", __DATE__, __TIME__);
#endif

	/* used for flag the initialize is finished */
	// Set event group 0 bit0 to halt other tasks
	setting_event_group = EVENT_GROUP_SET_BIT(EVENT_GROUP_0_INIT);
	event_group_bits = xEventGroupSetBits(event_group_0, setting_event_group);
	if ((event_group_bits & setting_event_group) == 0)
	{
		printf ("event group 0 setting error - init\n");
	}

	// delete the initialize task
	extern TaskHandle_t os_init_thread;
	vTaskDelete(os_init_thread);
//	printf(" Init thread not be deleted\n ");
	
	while(1)
	{
		vTaskDelay(pdMS_TO_TICKS(1000));
	}
}
